import { fileURLToPath, URL } from 'node:url';

import { defineConfig } from 'vite';
import vue from '@vitejs/plugin-vue';
import AutoImport from 'unplugin-auto-import/vite';
import Components from 'unplugin-vue-components/vite';
import { ElementPlusResolver } from 'unplugin-vue-components/resolvers';

// https://vitejs.dev/config/
export default defineConfig({
  plugins: [
    vue(),
    AutoImport({
      resolvers: [ElementPlusResolver()],
    }),
    Components({
      resolvers: [ElementPlusResolver()],
    }),
  ],
  resolve: {
    alias: {
      '@': fileURLToPath(new URL('./src', import.meta.url)),
    },
  },
  server: {
    host: '127.0.0.1',
    port: 4080,
    proxy: {
      '/api': {
        target: 'http://123.57.29.73:8088', // 接口的域名
        // target: 'http://www.solutionsjournalismcase.com',
        secure: false, // 如果是https接口，需要配置这个参数
        changeOrigin: true, // 如果接口跨域，需要进行这个参数配置
      },
      '/files': {
        target: 'http://123.57.29.73:8088', // 接口的域名
        // target: 'http://www.solutionsjournalismcase.com',
        secure: false, // 如果是https接口，需要配置这个参数
        changeOrigin: true, // 如果接口跨域，需要进行这个参数配置,
      },
      //图床
      '/smms-api': {
        target: 'https://smms.app/api/v2',
        changeOrigin: true,
        rewrite: (path) => path.replace(/^\/smms-api/, ''),
      },
    },
  },
});
